package org.example;


import java.util.ArrayList;
import java.util.List;

public class Test1 {
    //leetcode 242 有效的字母异位词 https://leetcode.cn/problems/valid-anagram/description/
    public boolean isAnagram(String s, String t) {
        if (s.length() != t.length()) return false;
        int[] hash1 = new int[26];
        int[] hash2 = new int[26];
        for (char c : t.toCharArray()) hash2[c - 'a']++;
        List<Integer> list = new ArrayList<>();
        for (char c : s.toCharArray()) {
            if (hash2[c - 'a'] == 0) return false;
            if (++hash1[c - 'a'] > hash2[c - 'a']) return false;
        }
        return true;
    }
}
